import request from '@/utils/request'
import type {
  userQueryParams,
  UserInfoResponse,
  updateUserParams,
} from '@/api/back-management/user/interface'
import type { Response, PageDataList } from '@/utils/type'

/**
 * 获取用户列表
 *
 * @param {userQueryParams} params 查询参数
 *
 */
export const queryUserList = (params: userQueryParams) => {
  return request('/system/user/query', {
    method: 'GET',
    params,
  }) as Promise<Response<PageDataList<UserInfoResponse>>>
}

/**
 * 新增用户
 *
 * @param {updateUserParams} params 更新参数
 *
 */
export const addUser = (params: updateUserParams) => {
  return request('/system/user/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<UserInfoResponse>>
}

/**
 * 更新用户
 *
 * @param {updateUserParams} params 更新参数
 *
 */
export const updateUser = (pkid: string, params: updateUserParams) => {
  return request(`/system/user/update/${pkid}`, {
    method: 'PUT',
    data: params,
  }) as Promise<Response<UserInfoResponse>>
}

/**
 * 修改密码
 *
 * @param {updateUserParams} params 更新参数
 *
 */
export const changeUserPassword = (params: updateUserParams) => {
  return request(`/system/user/updatePassword`, {
    method: 'POST',
    params,
  }) as Promise<Response<UserInfoResponse>>
}

/**
 * 获取在线用户列表
 *
 * @param {userQueryParams} params 查询参数
 *
 */
export const queryUserOnlineList = (
  params: userQueryParams
): Promise<Response<PageDataList<UserInfoResponse>>> => {
  return request('/system/user/online/query', {
    method: 'GET',
    params,
  })
}

/**
 * 强制下线
 */
export const outlineUser = (userId: string) => {
  return request('/system/user/notOnline', {
    method: 'GET',
    params: {
      userId: userId,
    },
  }) as Promise<Response<any>>
}
